package com.flong.desgin.patterns.openclose;

import lombok.val;

/**
 * @Author:liangjl
 * @Date: 2020/3/7-21:42
 * @Eamil:jilongliang@sina.com
 * @Description: 开闭原则
 */
public class Ocp {

    public static void main(String[] args) {
        val graphicEditor = new GraphicEditor();
        graphicEditor.drawRectangle(new Rectangle());
        graphicEditor.drawCircle(new Circle());
        graphicEditor.drawTriangle(new Triangle());

    }
}

class GraphicEditor {
    public void grawShape(Shape shape) {
        if (shape.m_type == 1) {
            drawRectangle(shape);
        } else if (shape.m_type == 2) {
            drawCircle(shape);
        }else if (shape.m_type == 3) {
            drawTriangle(shape);
        }
    }

    public void drawRectangle(Shape r) {
        System.out.println("矩形");
    }

    public void drawCircle(Shape r) {
        System.out.println("圆形");
    }

    public void drawTriangle(Shape r) {
        System.out.println("三角形");
    }

}

class Shape {
    public int m_type;
}

class Rectangle extends Shape {
    Rectangle() {
        super.m_type = 1;
    }
}

class Circle extends Shape {
    Circle() {
        super.m_type = 2;
    }
}

class Triangle extends Shape {
    Triangle() {
        super.m_type = 3;
    }
}